package interpreter;

/**
 * @Author: Doream
 * @Date: 2022/1/30 19:35
 */
// 减法表达式类
public class MinusExpression extends AbstractExpression {
    // -号左边的表达式
    private AbstractExpression left;
    // -号右边的表达式
    private AbstractExpression right;

    public MinusExpression(AbstractExpression left, AbstractExpression right) {
        this.left = left;
        this.right = right;
    }

    @Override
    public int interpret(Context context) {
        // 把-号左边的表达式减上上-号右边的表达式
        return left.interpret(context)-right.interpret(context);
    }

    @Override
    public String toString() {
        return "("+left.toString()+"-"+right.toString()+")";
    }
}
